# coding=utf-8
"""

"""
import yaml

from utils.do_path import CARD_CONF


# @Time    : 2024/12/12 17:03
# @Author  : ginger
# @Email   : gingerqgyy@outlook.com
# @Project : curl_conversion
# @File    : do_yml.py

class DoYml(object):
    __instance = False

    @classmethod
    def __new__(cls, *args, **kwargs):
        if cls.__instance:
            return cls
        else:
            cls.__instance = True
            return cls

    @classmethod
    def get(cls, _keys=None):
        """
        _keys 为空时, 获取全量数据
        _keys 可传 str 或 list / tuple
            str :            返回顶层 key 对应的 value
            list / tuple :   list 中的顺序与 yaml 中的 key 顺序保持一致, 任意一个 key 未匹配到时, 返回 None
        """
        _file = CARD_CONF
        with open(_file, encoding='utf8') as _f:
            _datas: dict = yaml.safe_load(_f)
            if not _keys:
                return _datas
            if isinstance(_keys, str):
                _keys = [_keys]
            for _key in _keys:
                _datas = _datas.get(_key)
                if not _datas:
                    return None
            return _datas


do_yml = DoYml()

if __name__ == '__main__':
    print(do_yml.get())
